<?php
/**
 * Created by Jayli.
 * User: Administrator
 * Date: 2018-03-07
 * Time: 14:46
 */

namespace App\Http\Controllers\Admin\Order;

use App\Http\Controllers\Admin\BaseController;
use Illuminate\Http\Request;

class OrderProductCommentController extends BaseController
{
    protected $api_url = [
        'index' => ['get', 'product_comments'],
        'show' => ['get', 'product_comments/%d'],
        'store' => ['post', 'product_comments'],
        'update' => ['put', 'product_comments/%d'],
        'destroy' => ['delete', 'product_comments/%d']
    ];

    protected $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    public function index()
    {
        //参数部分
        $search_params = $this->request->all(['product_name', 'shop_name', 'user_name', 'created_at', 'check_status']);
        $page = $this->request->get('page', 1);
        $params = [
            'search' => search_params($search_params),
            'searchJoin' => 'and',
            'page' => $page,
            'orderBy'=>'created_at',
            'sortedBy'=>'desc',
            'with' => 'orderProduct;user'
        ];

        //请求部分
        $ret = http_admin($this->api_url['index'])->send($params);

        //结果处理部分
        $data = paginate($this->request, $ret['data']);

        //回填搜索框值
        $data['search_params'] = $search_params;

        return view('Admin.order.evaluate_list', $data);
    }

    public function show($id)
    {
    }

    public function create()
    {
        //
    }

    public function store()
    {
        //
    }

    public function edit()
    {
        //
    }

    public function update($id)
    {
        $this->validate($this->request, [
            'type' => 'required|in:invalid'
        ]);
        $data = $this->request->all(['type']);
        $params = [];
        if($data['type'] == 'invalid'){
            $params['check_status'] = 3;
        }

        //请求部分
        $ret = http_admin($this->api_url['update'], [$id])->send($params);

        return $ret;
    }

    public function delete()
    {
        //
    }
}